﻿@{
    Layout = "/Views/Shared/_SubLayout.cshtml";
    ViewBag.Title = "所有訂單";
}
<script>
    $(document).ready(function () {
        $.fn.metro.onPrevClick = function () {
            window.location = "/Home";
        };

        loadOrders();
    });

    function changeOrder() {
        var id = $('.metro_grid_row.selected .orderID').html();

        if (id == undefined || id == '') {
            showMessage('請選擇需要修改的訂單');
        }
        else {
            window.location = "/Home/OrderEdit?id=" + id;
        }
    }
</script>
<script id="metroGridRowTemplate" type="text/x-jquery-tmpl">
    <div class="metro_grid_row">
        <div class="metro_grid_cell hide"><div class="orderID">${ID}</div></div>
        <div class="metro_grid_cell"><div>${Customer}</div></div>
        <div class="metro_grid_cell"><div>${DateStr}</div></div>
        <div class="metro_grid_cell"><div>${OrderDateStr}</div></div>
        <div class="metro_grid_cell"><div class="totalPrice" totalPrice="${TotalPrice}"></div></div>
        <div class="clear">
        </div>
    </div>
</script>
<script id="metroGridTemplate" type="text/x-jquery-tmpl">
    <div class="metro_grid">
        <div class="metro_grid_contain">
            <div class="metro_grid_header">
                <div class="metro_grid_column hide"><div></div>
                </div>
                <div class="metro_grid_column" data-width="auto">
                    <div>客戶</div></div>
                <div class="metro_grid_column" data-width="100">
                    <div>日期</div></div>
                <div class="metro_grid_column" data-width="100">
                    <div>下單日期</div></div>
                <div class="metro_grid_column" data-width="120">
                    <div>總計</div></div>
                <div class="clear">
                </div>
            </div>
            <div class="metro_grid_rows">
                {{tmpl(List) "#metroGridRowTemplate"}}
            </div>
        </div>
    </div>
</script>
<div id="OrderMgt">
    <div class="metro_toolbar">
        <div class="metro_input_contain">
            <a class="metro_input_btn" href="/Home/OrderEdit">新增訂單</a> <a class="metro_input_btn"
                onclick="changeOrder();">修改訂單</a>
        </div>
    </div>
</div>
<script>
    function loadOrders() {
        showLoading();
        var url = "/Home/GetOrders";
        $.ajax({
            url: url,         //请求链接 
            dataType: "json",
            success: function (result) {
                $('#metroGridTemplate').tmpl(result).appendTo($('#OrderMgt'));

                $('.totalPrice').each(function () {
                    $(this).html(formatNumber($(this).attr('totalPrice'), "#,###.00"));
                });

                $('.metro_grid').metro_grid();

                hideLoading();
            }
        });
    }
</script>
